package com.pms.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.pms.entity.ShareFile;
import com.pms.util.DBHelp;
import com.pms.util.RowMapper;

public class ShareFileDao {

	DBHelp<ShareFile> db = new DBHelp<ShareFile>();
	
	
	public void save(String id,String filename,String name,long filesize,String path,String createtime,String t_filetype_id,String t_user_id){
		String sql ="insert into t_file(id,filename,name,filesize,path,createtime,t_filetype_id,t_user_id) value(?,?,?,?,?,?,?,?)";
		db.executeSQL(sql, id,filename,name,filesize,path,createtime,t_filetype_id,t_user_id);
	}
	public List<ShareFile> findAll(String t_filetype_id){
		String sql = "select id,filename,name,filesize,createtime,t_filetype_id,t_user_id from t_file where t_filetype_id = ?";
		return db.executeQueryForList(sql, new ShareFileRowMapper(), t_filetype_id);
	}
	public ShareFile findById(String id){
		String sql = "select id,filename,name,filesize,createtime,t_filetype_id,t_user_id from t_file where id = ?";
		return db.executeQueryForObject(sql, new ShareFileRowMapper(), id);
	}
	
	public void del(String id){
		String sql = "delete from t_file where id = ?";
		db.executeSQL(sql, id);
	}
	
	
	public class ShareFileRowMapper implements RowMapper<ShareFile>{

		public ShareFile mapperRow(ResultSet rs) throws SQLException {
			ShareFile sharefile = new ShareFile();
			sharefile.setId(rs.getString("id"));
			sharefile.setFilename(rs.getString("filename"));
			sharefile.setName(rs.getString("name"));
			sharefile.setFilesize(rs.getLong("filesize"));
			sharefile.setCreatetime(rs.getString("createtime"));
			sharefile.setT_filetype_id(rs.getString("t_filetype_id"));
			sharefile.setT_user_id(rs.getString("t_user_id"));
			
			return sharefile;
		}
		
		
	}
	
	
	
	
	
	
	
	
	
}
